package com.smedi.ismedi.notification.core.infrastructure.config;

import com.smedi.ismedi.notification.core.infrastructure.constant.ConstantField;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@RequiredArgsConstructor
public class SmsClientConfig {
    @Value("${tencent-could.secretId}")
    private String secretId;

    @Value("${tencent-could.secretKey}")
    private String secretKey;

    @Bean
    public SmsClient getSmsClient() {
        log.info("配置腾讯云客户端");
        Credential cred = new Credential(secretId, secretKey);
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint(ConstantField.endPoint);
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);

        // 生成客户端
        SmsClient client = new SmsClient(cred, "", clientProfile);
        return client;
    }
}
